package examples;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

import com.hyperrealm.kiwi.ui.*;
import com.hyperrealm.kiwi.ui.model.*;
import com.hyperrealm.kiwi.ui.dialog.*;
import com.hyperrealm.kiwi.ui.propeditor.*;
import com.hyperrealm.kiwi.util.*;

public class PropertyTest extends KFrame implements ActionListener
{
  private PropertyModel model;
  private PropertyEditor editor;
  private KButton b_del;

  public static void main(String args[])
  {
    PropertyTest t = new PropertyTest();
    t.setVisible(true);
  }
  
  PropertyTest()
  {
    super("PropertyTest");
    JPanel p = getMainContainer();

    model = new PropertyModel();

    Property prop = new Property("Root", new TextPropertyType());
    model.setRoot(prop);

    Property prop1 = new Property("Child 1", new TextPropertyType());
    model.addChild(prop, prop1);

    Property prop2 = new Property("Child 2", new TextPropertyType());
    model.addChild(prop1, prop2);

    Property prop3 = new Property("Child 3", new TextPropertyType());
    model.addChild(prop2, prop3);

    Property prop4 = new Property("Child 4", new TextPropertyType());
    prop4.setValue("Hello");
    model.addChild(prop3, prop4);

    editor = new PropertyEditor();
    editor.setModel(model);

    p.setLayout(new BorderLayout(5, 5));
    p.add("Center", editor);

    b_del = new KButton("Delete");
    b_del.addActionListener(this);
    p.add("South", b_del);

    editor.expand();
    pack();
  }

  public void actionPerformed(ActionEvent evt)
  {
    Object o = evt.getSource();

    if(o == b_del) {
      Property prop = editor.getSelectedProperty();
      if(prop != null)
        model.removeNode(prop);
    }
  }  
}
